package cn.iocoder.yudao.module.wine.controller.admin.stockstore;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.admin.stockstore.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.stockstore.StockStoreDO;
import cn.iocoder.yudao.module.wine.service.stockstore.StockStoreService;

@Tag(name = "管理后台 - 仓库信息")
@RestController
@RequestMapping("/wine/stock-store")
@Validated
public class StockStoreController {

    @Resource
    private StockStoreService stockStoreService;

    @PostMapping("/create")
    @Operation(summary = "创建仓库信息")
    @PreAuthorize("@ss.hasPermission('wine:stock-store:create')")
    public CommonResult<Long> createStockStore(@Valid @RequestBody StockStoreSaveReqVO createReqVO) {
        return success(stockStoreService.createStockStore(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新仓库信息")
    @PreAuthorize("@ss.hasPermission('wine:stock-store:update')")
    public CommonResult<Boolean> updateStockStore(@Valid @RequestBody StockStoreSaveReqVO updateReqVO) {
        stockStoreService.updateStockStore(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除仓库信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('wine:stock-store:delete')")
    public CommonResult<Boolean> deleteStockStore(@RequestParam("id") Long id) {
        stockStoreService.deleteStockStore(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得仓库信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('wine:stock-store:query')")
    public CommonResult<StockStoreRespVO> getStockStore(@RequestParam("id") Long id) {
        StockStoreDO stockStore = stockStoreService.getStockStore(id);
        return success(BeanUtils.toBean(stockStore, StockStoreRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得仓库信息分页")
    @PreAuthorize("@ss.hasPermission('wine:stock-store:query')")
    public CommonResult<PageResult<StockStoreRespVO>> getStockStorePage(@Valid StockStorePageReqVO pageReqVO) {
        PageResult<StockStoreRespVO> pageResult = stockStoreService.getStockStorePage(pageReqVO);
        return success(pageResult);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出仓库信息 Excel")
//    @PreAuthorize("@ss.hasPermission('wine:stock-store:export')")
//    @OperateLog(type = EXPORT)
//    public void exportStockStoreExcel(@Valid StockStorePageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<StockStoreDO> list = stockStoreService.getStockStorePage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "仓库信息.xls", "数据", StockStoreRespVO.class,
//                        BeanUtils.toBean(list, StockStoreRespVO.class));
//    }

}
